version: "3.9"

services:
  server:
    build:
      context: .
      target: discovery-service
    container_name: discovery-service
    environment:
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-service:8761/eureka
    ports:
      - '8761:8761'

  postgres_media_service:
    image: postgres:15.6-alpine3.19
    container_name: media_db
    environment:
      POSTGRES_DB: "media_db"
      POSTGRES_USER: "mediadata"
      POSTGRES_PASSWORD: "mediadata"
    volumes:
      - .\media-service\src\main\resources\db-init:/docker-entrypoint-initdb.d
    ports:
      - "5433:5432"

  postgres_user_service:
    image: postgres:15.6-alpine3.19
    container_name: users_db
    environment:
      POSTGRES_DB: "users_db"
      POSTGRES_USER: "userdata"
      POSTGRES_PASSWORD: "userdata"
    volumes:
      - .\user-service\src\main\resources\db-init:/docker-entrypoint-initdb.d
    ports:
      - "5434:5432"

  client_media_service:
    build:
      context: .
      target: media-service
    container_name: media-service
    depends_on:
      - postgres_media_service
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres_media_service/media_db?currentSchema=media
      - SPRING_DATASOURCE_USERNAME=mediadata
      - SPRING_DATASOURCE_PASSWORD=mediadata
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-service:8761/eureka

  client_user_service:
    build:
      context: .
      target: user-service
    container_name: user-service
    depends_on:
      - postgres_user_service
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres_user_service/users_db?currentSchema=users_data
      - SPRING_DATASOURCE_USERNAME=userdata
      - SPRING_DATASOURCE_PASSWORD=userdata
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-service:8761/eureka

  gateway:
    build:
      context: .
      target: gateway-service
    container_name: gateway-service
    environment:
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-service:8761/eureka
    ports:
      - '8765:8765'
